//
// Created by jsjxsy on 2022/8/10.
//
//
#include<iostream>
#include <memory>
using namespace std;
class A {
 public:
  A();
  ~A();
  int score = 10;
 private:

};
A::A() {
  cout << "A()" << endl;
}
A::~A() {
  cout << "~A()" << endl;
}

int main(void) {
  //方式1 栈
  A a1;
  cout << "---------" << endl;
  //方式2 堆
  A *a2 = new A();
  delete a2;//必须delete，否则内存泄漏
  cout << "---------" << endl;
  unique_ptr<A> p1(new A());
  A *a3 = p1.get();
  cout << "a3->score=" << a3->score << endl;
  //error
  //unique_ptr<A> p2 = new A();
  unique_ptr<A> p2 = move(p1);
  //p1 nullptr
  cout << "p1.get()=" << p1.get() << endl;
  //p2
  cout << "p2.get()->score=" << p2.get()->score << endl;
  //
  auto p3 = unique_ptr<A>(new A());
  cout<< "p3="<<p3.get()<<endl;
  return 0;
}

